package com.huaju.web.controller;

import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.propertyeditors.CustomDateEditor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.huaju.enity.Account;
import com.huaju.enity.Admin;
import com.huaju.enity.AdminNotice;
import com.huaju.enity.Adminlog;
import com.huaju.enity.Backuprecord;
import com.huaju.enity.Bankcard;
import com.huaju.enity.Company;
import com.huaju.enity.Department;
import com.huaju.enity.Incomelist;
import com.huaju.enity.Incometype;
import com.huaju.enity.Menu;
import com.huaju.enity.Notice;
import com.huaju.enity.Ntype;
import com.huaju.enity.Payoutlist;
import com.huaju.enity.Paytype;
import com.huaju.enity.Position;
import com.huaju.enity.Profit;
import com.huaju.enity.Rate;
import com.huaju.enity.Recoverrecord;
import com.huaju.enity.RoleType;
import com.huaju.enity.Smsrecord;
import com.huaju.enity.Smstype;
import com.huaju.enity.SubMenu;
import com.huaju.enity.Subcompany;
import com.huaju.enity.Systemlog;
import com.huaju.enity.UserRole;
import com.huaju.enity.Wages;
import com.huaju.manager.WebMananger;
import com.jinzht.tools.Config;
import com.jinzht.tools.FileUtil;
import com.jinzht.tools.MessageType;
import com.jinzht.tools.MsgUtil;
import com.jinzht.tools.Tools;
import com.wx.tools.AKConfig;
import com.wx.tools.DateUtils;
import com.wx.tools.wx.TestWChatPayToUser;

@Controller
public class AdminController extends BaseController {

	@Autowired
	private WebMananger webMananger;

	@InitBinder
	protected void initBinder(HttpServletRequest request,
			ServletRequestDataBinder binder) throws Exception {
		binder.registerCustomEditor(Date.class, new CustomDateEditor(
				new SimpleDateFormat("yyyy-MM-dd"), true));
	}

	/***
	 * ---------------------------------------------后端管理系统------------------
	 * -------------------------
	 ***/
	/*
	 * @InitBinder public void initBinder(ServletRequestDataBinder bin) {
	 * SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
	 * CustomDateEditor cust = new CustomDateEditor(sdf, true);
	 * bin.registerCustomEditor(Date.class, cust); }
	 */
	@RequestMapping(value = "")
	public void index_action(ModelMap map, HttpSession session,
			ServletRequest request, ServletResponse response) {
		session.setAttribute("userId", "1");
		try {
			request.getRequestDispatcher("index.htm")
					.forward(request, response);
		} catch (ServletException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@RequestMapping(value = "/manager/index")
	public void index_action1(ModelMap map, HttpSession session,
			ServletRequest request, ServletResponse response) {
		session.setAttribute("userId", "1");
		try {
			request.getRequestDispatcher("web/login.html").forward(request,
					response);
		} catch (ServletException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@RequestMapping(value = "/manager/")
	public void index(ModelMap map, HttpSession session,
			ServletRequest request, ServletResponse response) {
		session.setAttribute("userId", "1");
		try {
			request.getRequestDispatcher("web/main2.html").forward(request,
					response);

		} catch (ServletException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	/**
	 * 管理系统首页
	 * 
	 * @param map
	 * @param session
	 * @param request
	 * @param response
	 */
	@RequestMapping(value = "/manager/admin")
	public void admin(ModelMap map, HttpSession session,
			ServletRequest request, ServletResponse response) {
		session.setAttribute("userId", "1");
		try {
			request.getRequestDispatcher("web/main2.html").forward(request,
					response);
		} catch (ServletException | IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	@RequestMapping(value = "/manager/adminLogin")
	@ResponseBody
	public Map admin(ModelMap map, HttpSession session, String account,
			String password, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		List<Admin> admins = this.webMananger.getAdminDAO().findByLoginname(
				account);
		if (admins != null && admins.size() > 0) {
			Admin admin = admins.get(0);
			if (admin.getLoginpwd().equalsIgnoreCase(password)) {

				session.setAttribute("adminId", admin.getAid());
				this.status = 200;
				this.message = "登录成功!";
				this.result.put("action", "./manager/admin.action");

				Adminlog log = new Adminlog();
				log.setLogUser(admin.getName());
				log.setLogMsg(admin.getRoleType().getName()
						+ "于"
						+ DateUtils.dateToString(new Date(),
								"yyyy-MM-dd HH:MM:ss") + "登录系统");
				log.setLogTime(new Date());
				log.setLogType("系统登录");
				log.setIsSuccess((short) 1);

				session.setAttribute("admin", admin);
				this.webMananger.getAdminLogDAO().save(log);

				return getResult();
			}

		}

		this.status = 201;
		this.message = "账号或密码错误！";

		return getResult();
	}

	@RequestMapping(value = "/manager/updateAdminPwd")
	@ResponseBody
	public Map updateAdminPwd(ModelMap map, HttpSession session,
			String password, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Integer adminId = (Integer) session.getAttribute("adminId");
		Admin admin = this.webMananger.getAdminDAO().findById(adminId);
		if (!password.equalsIgnoreCase("")) {

			admin.setLoginpwd(password);
			this.webMananger.getAdminDAO().saveOrUpdate(admin);
			this.status = 200;

			Adminlog log = new Adminlog();
			log.setLogUser(admin.getName());
			log.setLogMsg(admin.getRoleType().getName() + "于"
					+ DateUtils.dateToString(new Date(), "yyyy-MM-dd HH:MM:ss")
					+ "修改密码");
			log.setLogTime(new Date());
			log.setLogType("管理员修改密码");
			log.setIsSuccess((short) 1);

			this.webMananger.getAdminLogDAO().save(log);

			this.message = "密码修改成功";
			return getResult();
		}
		this.status = 201;
		this.message = "密码不能为空！";

		return getResult();
	}

	/************************************************************* 用户管理 **********************************************************************************/
	@RequestMapping(value = "/manager/UserList")
	@ResponseBody
	public Map UserList(
			ModelMap map,
			HttpSession session,

			@RequestParam(value = "type", required = false) Integer type,

			@RequestParam(value = "draw", required = false) Integer draw,

			@RequestParam(value = "start", required = false) Integer start,
			@RequestParam(value = "page", required = false) Integer page,

			@RequestParam(value = "length", required = false) Integer length,

			@RequestParam(value = "search", required = false) String search,
			@RequestParam(value = "search[value]", required = false) String value,
			ServletRequest request, ServletResponse response) {

		if (start == null) {
			if (page != null) {
				start = page;
			} else {
				start = 0;
			}
		}

		if (length == null) {
			length = 100;
		}

		this.result = new HashMap();

		Admin admin = (Admin) session.getAttribute("admin");
		List<Account> ll = new ArrayList();
		Integer size = 0;
		if (admin.getSubcompany() != null) {
			if (search == null) {
				search = value;
			}
			size = this.webMananger.getAccountDAO().countAll("comId",
					admin.getSubcompany().getSid(), "name", search);
			ll = this.webMananger.getAccountDAO().findByPage(start, length,
					"comId", admin.getSubcompany().getSid(), "name", search);
		} else {
			size = this.webMananger.getAccountDAO().countAll();
			ll = this.webMananger.getAccountDAO().findByPage(start, length);
		}

		// 计算余额
		for (Account account : ll) {
			// 所有收入
			Double allcome = 0.00;
			allcome = this.webMananger.getIncomeListDAO().getAllIncomeByUser(
					account.getAid());
			// 所有支出
			Double allpay = 0.00;
			allpay = this.webMananger.getPayoutListDAO().getAllPayoutByUser(
					account.getAid(), 1);
			// 总收益利息
			Double incomePro = 0.00;
			incomePro = this.webMananger.getProfitDAO().getIncomeProfitByUser(
					account.getAid(), 1);
			// 总支出利息
			Double payPro = 0.00;
			payPro = this.webMananger.getProfitDAO().getPayProfitByUser(
					account.getAid(), 1);
			// 现有利息
			Double nowPro = incomePro - payPro;

			// 当前余额（本金）
			Double balance = allcome - allpay;

			// 当前余额（本金）
			Double allBalance = allcome - allpay + nowPro;

			// 小数保留两位
			allBalance = Tools.M2(allBalance);
			balance = Tools.M2(balance);
			nowPro = Tools.M2(nowPro);

			account.setBalance(allBalance);
			account.setProfit(nowPro);
			account.setPrincipal(balance);

			this.webMananger.getAccountDAO().attachDirty(account);

		}

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/formatUserList")
	@ResponseBody
	public Map formatUserList(ModelMap map, HttpSession session,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List<Account> ll = this.webMananger.getAccountDAO().findAll();
		for (Account account : ll) {
			if (account.getPosition() != null) {
				// account.setComId(account.getPosition().getDepartment().getSubcompany().getSid());
				List res = this.webMananger.getPositionDAO().findBySQLProperty(
						"pid", account.getPosition().getPid());
				for (Object ob : res) {
					Object[] ob1 = (Object[]) ob;
					System.out
							.println(ob1[0] + " | " + ob1[1] + " | " + ob1[2]);
					Integer did = (Integer) ob1[1];
					List dids = this.webMananger.getDepartmentDAO()
							.findBySQLProperty("did", did);
					for (Object object : dids) {
						Object[] ob2 = (Object[]) object;
						System.out.println(ob2[0] + " | " + ob2[1] + " | "
								+ ob2[2]);
						Integer sid = (Integer) ob2[1];

						account.setComId(sid);
					}
				}
				this.webMananger.getAccountDAO().saveOrUpdate(account);
			}
		}

		List<Bankcard> bankCars = this.webMananger.getBankCardDAO().findAll();
		for (Bankcard bankcard : bankCars) {
			bankcard.setComId(bankcard.getAccount().getComId());

			this.webMananger.getBankCardDAO().saveOrUpdate(bankcard);
		}

		List<Incomelist> incomeList = this.webMananger.getIncomeListDAO()
				.findAll();
		for (Incomelist incomelist2 : incomeList) {
			incomelist2.setComId(incomelist2.getAccount().getComId());
			this.webMananger.getIncomeListDAO().saveOrUpdate(incomelist2);
		}

		List<Payoutlist> payoutList = this.webMananger.getPayoutListDAO()
				.findAll();
		for (Payoutlist payoutlist2 : payoutList) {
			payoutlist2.setComId(payoutlist2.getAccount().getComId());
			this.webMananger.getPayoutListDAO().saveOrUpdate(payoutlist2);
		}

		List<Profit> profits = this.webMananger.getProfitDAO().findAll();
		for (Profit profit : profits) {
			profit.setComId(profit.getAccount().getComId());

			this.webMananger.getProfitDAO().saveOrUpdate(profit);
		}

		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getUserDetail")
	@ResponseBody
	public Map getUserDetail(ModelMap map, HttpSession session, Integer type,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Account inn = null;
		if (contentId != null) {
			inn = this.webMananger.getAccountDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getBankCardDetail")
	@ResponseBody
	public Map getBankCardDetail(ModelMap map, HttpSession session,
			Integer type, Integer contentId, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Bankcard inn = null;
		if (contentId != null) {
			inn = this.webMananger.getBankCardDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getUserWages")
	@ResponseBody
	public Map getUserWages(ModelMap map, HttpSession session, Integer type,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Wages inn = null;
		if (contentId != null) {
			inn = this.webMananger.getWagesDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/***
	 * 发放工资
	 * 
	 * @param map
	 * @param session
	 * @param sendall
	 *            是否全员发送短信通知
	 * @param contentId
	 *            工资记录id
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/manager/settleWages")
	@ResponseBody
	public Map settleWages(ModelMap map, HttpSession session, String sendall,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Wages inn = null;
		Admin admin = (Admin) session.getAttribute("admin");
		if (contentId != null) {
			inn = this.webMananger.getWagesDAO().findById(contentId);
			// 判断是否已经发过本月工资
			if (inn != null && inn.getStatus() != 1) {


				// 生成收入记录
				Incomelist income = new Incomelist();
				income.setAccount(inn.getAccount());
				Incometype type = new Incometype();
				type.setTid(1);

				income.setIncometype(type);
				income.setImoney(inn.getWnum());
				income.setIdesc(inn.getWdesc());
				income.setItime(new Date());
				income.setSuccess((short) 1);
				income.setSuccessTime(new Date());
				// 如果管理员已分配公司
				if (inn.getAccount().getComId() != null) {
					income.setComId(inn.getAccount().getComId());
				}

				this.webMananger.getIncomeListDAO().save(income);
				
				inn.setStatus(1);
				this.webMananger.getWagesDAO().saveOrUpdate(inn);

				String content = String.format(Config.SMS_HAVE_SEND_WAGE, inn
						.getAccount().getName(), inn.getWdesc(), DateUtils
						.dateToString(new Date(), "yyyy-MM-dd HH:MM:ss"));

				Tools.sendMessage(content, inn.getAccount().getTel());
				// 生成通知
				generateNotice(inn);

				// 记录日志
				Systemlog log = new Systemlog();
				log.setAddTime(new Date());
				log.setContent(inn.getAccount().getName()
						+ "发放工资"
						+ income.getImoney()
						+ DateUtils.dateToString(new Date(),
								"yyyy-MM-dd HH:MM:ss"));
				log.setLevel("发放工资");

				this.webMananger.getSystemlogDAO().save(log);
				this.result.put("data", inn);
			}

		} else {
			List<Wages> ll = null;
			if (admin.getSubcompany() != null) {
				Map mm = new HashMap();
				mm.put("status", 0);
				mm.put("comId", admin.getSubcompany().getSid());
				ll = this.webMananger.getWagesDAO().findByProPage(mm, 0,
						100000, "etr", "");
			} else {
				ll = this.webMananger.getWagesDAO().findByProperty("status", 0);
			}
			for (Wages wage : ll) {
				if (wage.getWnum() != null && wage.getStatus() != 1) {
					// 生成收入记录
					Incomelist income = new Incomelist();
					income.setAccount(wage.getAccount());
					Incometype type = new Incometype();
					type.setTid(1);

					income.setIncometype(type);
					income.setImoney(wage.getWnum());
					income.setIdesc(wage.getWdesc());
					income.setItime(new Date());
					income.setSuccess((short) 1);
					income.setSuccessTime(new Date());
					income.setComId(admin.getSubcompany().getSid());

					this.webMananger.getIncomeListDAO().save(income);

					wage.setStatus(1);
					this.webMananger.getWagesDAO().saveOrUpdate(wage);

					if (sendall != null && sendall.equalsIgnoreCase("on")) {
						String content = String.format(
								Config.SMS_HAVE_SEND_WAGE, wage.getAccount()
										.getName(), wage.getWdesc(), DateUtils
										.dateToString(new Date(),
												"yyyy-MM-dd HH:MM:ss"));

						System.out.println("开始导入:"
								+ wage.getAccount().getName());
						System.out.println(wage.getAccount().getName());
						Tools.sendMessage(content, wage.getAccount().getTel());
					}
					// 生成通知
					generateNotice(wage);
					// 记录日志
					Systemlog log = new Systemlog();
					log.setAddTime(new Date());
					log.setContent(inn.getAccount().getName()
							+ "发放工资"
							+ income.getImoney()
							+ DateUtils.dateToString(new Date(),
									"yyyy-MM-dd HH:MM:ss"));
					log.setLevel("发放工资");
					this.webMananger.getSystemlogDAO().save(log);
				}
			}
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	private void generateNotice(Wages wage) {
		// 生成通知
		Notice notice = new Notice();
		notice.setAccount(wage.getAccount());
		notice.setIsRead(0);
		notice.setNauthor("恒丰掌中宝");

		String ncontent = String.format(Config.SMS_HAVE_SEND_WAGE, wage
				.getAccount().getName(), wage.getWdesc(), DateUtils
				.dateToString(new Date(), "yyyy-MM-dd HH:MM:ss"));

		Ntype ntype = new Ntype();
		ntype.setNid(1);

		notice.setNcontent(ncontent);
		notice.setNtime(new Date());
		notice.setNtitle("工资发放通知");
		notice.setNtype(ntype);

		this.webMananger.getNoticeDAO().save(notice);
	}

	@RequestMapping(value = "/manager/analysisSettleWages")
	@ResponseBody
	public Map getSettleWages(ModelMap map, HttpSession session,
			Integer sendall, Integer contentId, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Admin admin = (Admin) session.getAttribute("admin");
		List list = null;
		if (admin.getSubcompany() != null) {
			list = this.webMananger.getWagesDAO().findAnalysis(
					admin.getSubcompany().getSid());
		} else {
			list = this.webMananger.getWagesDAO().findAnalysis(null);
		}
		Object[] objects = (Object[]) list.get(0);

		this.result.put("total", objects[0]);
		this.result.put("totalNum", objects[1]);
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/analysisTotal")
	@ResponseBody
	public Map analysisTotal(ModelMap map, HttpSession session,
			Integer sendall, Integer contentId, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Admin admin = (Admin) session.getAttribute("admin");
		List list = null;
		List payoutList = null;
		List profitList = null; // 总计利息
		List profitNoList = null; // 未提现利息
		String dateStr = DateUtils.dateToString(new Date(), "yyyy-MM");
		dateStr += "-01";
		if (admin.getSubcompany() != null) {
			list = this.webMananger.getIncomeListDAO().findTotalAnalysis(
					admin.getSubcompany().getSid(), dateStr);
			payoutList = this.webMananger.getPayoutListDAO().findTotalAnalysis(
					admin.getSubcompany().getSid(), dateStr);
			profitList = this.webMananger.getProfitDAO().findTotalAnalysis(
					admin.getSubcompany().getSid(), dateStr, 5);
			profitNoList = this.webMananger.getProfitDAO().findTotalAnalysis(
					admin.getSubcompany().getSid(), dateStr, 5);
		} else {
			list = this.webMananger.getIncomeListDAO().findTotalAnalysis(null,
					dateStr);
			payoutList = this.webMananger.getPayoutListDAO().findTotalAnalysis(
					null, dateStr);
			profitList = this.webMananger.getProfitDAO().findTotalAnalysis(
					null, dateStr, 5);
			profitNoList = this.webMananger.getProfitDAO().findTotalAnalysis(
					null, dateStr, 3);
		}
		Object[] objects = (Object[]) list.get(0);
		Object[] objectsPay = (Object[]) payoutList.get(0);
		Object[] objectsPro = (Object[]) profitList.get(0);
		Object[] objectsNoPro = (Object[]) profitNoList.get(0);

		Double total = 0.0;
		Double totalPay = 0.0;
		Double totalPro = 0.0;
		Double totalNoPro = 0.0;
		if (objects[1] != null) {
			total = Double.valueOf(objects[1].toString()) / 1.0;
			total = Tools.M2(total);
		}
		if (objectsPay[1] != null) {
			totalPay = Double.valueOf(objectsPay[1].toString());
			totalPay = Tools.M2(totalPay);
		}
		if (objectsPro[1] != null) {
			totalPro = Double.valueOf(objectsPro[1].toString()) / 1.0;
			totalPro = Tools.M2(totalPro);
		}
		if (objectsNoPro[1] != null) {
			totalNoPro = Double.valueOf(objectsNoPro[1].toString()) / 1.0;
			totalNoPro = Tools.M2(totalPro - totalNoPro);
		}

		this.result.put("totalCount", objects[0] == null ? 0 : objects[0]);
		this.result.put("totalMoney", total);
		this.result.put("monthTXMoney", totalPay);
		this.result.put("monthLCMoney", totalPro);
		this.result.put("monthLCNoMoney", totalNoPro);
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getRate")
	@ResponseBody
	public Map getRate(ModelMap map, HttpSession session, Integer type,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Rate inn = null;
		if (contentId != null) {
			inn = this.webMananger.getRateDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getIncomeDetail")
	@ResponseBody
	public Map getIncomeDetail(ModelMap map, HttpSession session, Integer type,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Incomelist inn = null;
		if (contentId != null) {
			inn = this.webMananger.getIncomeListDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getOutcomeDetail")
	@ResponseBody
	public Map getOutcomeDetail(ModelMap map, HttpSession session,
			Integer type, Integer contentId, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Payoutlist inn = null;
		if (contentId != null) {
			inn = this.webMananger.getPayoutListDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getProfitDetail")
	@ResponseBody
	public Map getProfitDetail(ModelMap map, HttpSession session, Integer type,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Profit inn = null;
		if (contentId != null) {
			inn = this.webMananger.getProfitDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/***
	 * 批量校验汇款
	 * 
	 * @param map
	 * @param session
	 * @param contentId
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/manager/auditOrderRecords")
	@ResponseBody
	public Map auditOrderRecords(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		System.out.println(DateUtils.dateToString(new Date(),
				"yyyy-MM-dd HH:mm:ss"));
		List<Payoutlist> list = this.webMananger.getPayoutListDAO()
				.findByProperty("success", (short) 0);
		for (Payoutlist payoutlist : list) {
			if (payoutlist.getSuccess() == 0) {
				// boolean wxPayResult = false;
				// 发起微信企业零钱体现
				// 校验余额是否足够
				Account user = payoutlist.getAccount();
				// 所有收入
				Double allcome = 0.00;
				allcome = this.webMananger.getIncomeListDAO()
						.getAllIncomeByUser(user.getAid());
				// 所有支出
				Double allpay = 0.00;
				allpay = this.webMananger.getPayoutListDAO()
						.getAllPayoutByUser(user.getAid(), 1);
				// 总收益利息
				Double incomePro = 0.00;
				incomePro = this.webMananger.getProfitDAO()
						.getIncomeProfitByUser(user.getAid(), 1);
				// 总支出利息
				Double payPro = 0.00;
				payPro = this.webMananger.getProfitDAO().getPayProfitByUser(
						user.getAid(), 1);
				// 现有利息
				Double nowPro = incomePro - payPro;

				// 当前余额（本金）
				Double balance = allcome - allpay;

				// 当前余额（本金）
				Double allBalance = allcome - allpay + nowPro;

				System.out.println("uid:" + user.getAid());
				System.out.println("当前余额:" + allBalance);
				if (allBalance >= payoutlist.getPmoney()) {
					Map result = null;
					try {
						result = TestWChatPayToUser.wechatPayForUser(
								((int) (payoutlist.getPmoney() * 100)) + "",
								payoutlist.getPayCode(),
								payoutlist.getOpenId(), payoutlist.getPdesc());
					} catch (Exception e) {
						// TODO Auto-generated catch
						// block
						// e.printStackTrace();
						result = null;
					}

					if (result != null) {
						Systemlog log = new Systemlog();
						log.setAddTime(new Date());
						String content = "";

						String return_code = result.get("return_code")
								.toString();
						String result_code = result.get("result_code")
								.toString();
						content += return_code + ":" + result_code;

						if (return_code.equals("SUCCESS")) {
							if (result_code.equals("SUCCESS")) {
								payoutlist.setSuccess((short) 1);
								payoutlist.setSuccessTime(new Date());

								this.webMananger.getPayoutListDAO()
										.attachDirty(payoutlist);
								this.status = 200;
								sendMessageToUser(payoutlist.getAccount(),
										payoutlist.getPtime(),
										payoutlist.getPmoney());

								System.out.println("转账成功:" + return_code + ":"
										+ result_code + ":" + user.getName());
								System.out.println("转账成功:" + return_code + ":"
										+ result_code + ":" + user.getName());
								log.setExtr(user.getName()
										+ payoutlist.getPayCode());
								log.setLevel("本金转账成功！");
							} else {
								String err_code = result.get("err_code")
										.toString();
								String err_code_des = result
										.get("err_code_des").toString();
								System.out.println("转账失败:" + err_code + ":"
										+ err_code_des);
								if (err_code.equals("AMOUNT_LIMIT")) {
									payoutlist.setSuccess((short) 4);
									this.webMananger.getPayoutListDAO()
											.attachDirty(payoutlist);
								} else if (err_code.equals("NOTENOUGH")) {
									// 判断当日是否已经发送短信通知
									sendNoEnoughMessageToAdmin();
								}

								content += err_code + ":" + err_code_des;
								log.setLevel("本金转账失败！");
								log.setExtr(user.getName()
										+ payoutlist.getPayCode());
							}

							log.setContent(content);
							this.webMananger.getSystemlogDAO().save(log);
						}

					} else {
						/*
						 * payoutlist.setSuccess((short) 4);
						 * payoutlist.setExtr(payResultStr);
						 * this.webMananger.getPayoutListDAO
						 * ().attachDirty(payoutlist);
						 */
					}
				} else {

					System.out.println("非法数据:" + user.getName());
					payoutlist.setSuccess((short) 3);
					this.webMananger.getPayoutListDAO().attachDirty(payoutlist);
					sendMessageToTec(payoutlist.getPid(), user.getName(), "本金");

					Systemlog log = new Systemlog();
					log.setAddTime(new Date());
					log.setContent("出现非法数据:余额小于提现");
					log.setExtr(user.getName() + ":" + payoutlist.getPayCode());
					log.setLevel("本金提现大于余额");

					this.webMananger.getSystemlogDAO().save(log);
				}

			}
		}

		List<Profit> ll = this.webMananger.getProfitDAO().findByProperty(
				"success", (short) 0);

		for (Profit payoutlist : ll) {
			if (payoutlist.getSuccess() == 0) {
				// boolean wxPayResult = false;
				// 校验余额是否足够
				Account user = payoutlist.getAccount();
				// 发起微信企业零钱体现
				// 所有收入
				Double allcome = 0.00;
				allcome = this.webMananger.getIncomeListDAO()
						.getAllIncomeByUser(user.getAid());
				// 所有支出
				Double allpay = 0.00;
				allpay = this.webMananger.getPayoutListDAO()
						.getAllPayoutByUser(user.getAid(), 1);
				// 总收益利息
				Double incomePro = 0.00;
				incomePro = this.webMananger.getProfitDAO()
						.getIncomeProfitByUser(user.getAid(), 1);
				// 总支出利息
				Double payPro = 0.00;
				payPro = this.webMananger.getProfitDAO().getPayProfitByUser(
						user.getAid(), 1);
				// 现有利息
				Double nowPro = incomePro - payPro;

				// 当前余额（本金）
				Double balance = allcome - allpay;

				// 当前余额（本金）
				Double allBalance = allcome - allpay + nowPro;

				System.out.println("uid:" + user.getAid());
				System.out.println("当前余额:" + allBalance);
				if (allBalance >= payoutlist.getImoney()) {

					Map result = null;
					try {
						result = TestWChatPayToUser.wechatPayForUser(
								((int) (payoutlist.getImoney() * 100)) + "",
								payoutlist.getPayCode(),
								payoutlist.getOpenId(), payoutlist.getIdesc());
					} catch (Exception e) { // TODO Auto-generated catch
											// block
						e.printStackTrace();
					}
					if (result != null) {
						Systemlog log = new Systemlog();
						log.setAddTime(new Date());
						String content = "";

						String return_code = result.get("return_code")
								.toString();
						String result_code = result.get("result_code")
								.toString();
						content += return_code + ":" + result_code;

						if (return_code.equals("SUCCESS")) {
							if (result_code.equals("SUCCESS")) {
								payoutlist.setSuccess((short) 1);
								payoutlist.setSuccessTime(new Date());

								this.webMananger.getProfitDAO().attachDirty(
										payoutlist);
								this.status = 200;
								sendMessageToUser(payoutlist.getAccount(),
										payoutlist.getItime(),
										payoutlist.getImoney());

								System.out.println("转账成功:" + return_code + ":"
										+ result_code + ":" + user.getName());
								log.setExtr(user.getName()
										+ payoutlist.getPayCode());
								log.setLevel("利息转账成功！");
							} else {
								String err_code = result.get("err_code")
										.toString();
								String err_code_des = result
										.get("err_code_des").toString();
								System.out.println("转账失败:" + err_code + ":"
										+ err_code_des);
								if (err_code.equals("AMOUNT_LIMIT")) {
									payoutlist.setSuccess((short) 4);
									this.webMananger.getProfitDAO()
											.attachDirty(payoutlist);

								} else if (err_code.equals("NOTENOUGH")) {
									// 判断当日是否已经发送短信通知
									sendNoEnoughMessageToAdmin();
								}

								content += err_code + ":" + err_code_des;
								log.setLevel("利息转账失败！");
								log.setExtr(user.getName()
										+ payoutlist.getPayCode());
							}

							log.setContent(content);
							this.webMananger.getSystemlogDAO().save(log);
						}

					}
				} else {
					System.out.println("非法数据:" + user.getName());
					payoutlist.setSuccess((short) 3);
					this.webMananger.getProfitDAO().attachDirty(payoutlist);
					sendMessageToTec(payoutlist.getPid(), user.getName(), "利息");

					Systemlog log = new Systemlog();
					log.setAddTime(new Date());
					log.setContent("出现非法数据:余额小于提现");
					log.setExtr(user.getName() + ":" + payoutlist.getPayCode());
					log.setLevel("利息提现大于余额");

					this.webMananger.getSystemlogDAO().save(log);
				}
			}
		}
		System.out.println("任务执行完毕:");
		return this.getResult();
	}

	/***
	 * 定时任务
	 * 
	 * @param map
	 * @param session
	 * @param type
	 * @param contentId
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/manager/ScheduledProfile")
	@ResponseBody
	public Map ScheduledProfile(ModelMap map, HttpSession session,
			Integer type, Integer contentId, ServletRequest request,
			ServletResponse response) {
		System.out.println("开始执行任务:");
		this.result = new HashMap();
		short isSuccess = 1;
		List<Rate> rates = this.webMananger.getRateDAO().findByProperty(
				"isUse", isSuccess);

		if (rates != null && rates.size() > 0) {
			Rate rate = rates.get(0);
			List<Account> users = this.webMananger.getAccountDAO().findAll();
			for (Account user : users) {
				if (user.getIsjob() == 1) {

					// 所有收入
					Double allcome = 0.00;
					allcome = this.webMananger.getIncomeListDAO()
							.getAllIncomeByUser(user.getAid());
					// 所有支出
					Double allpay = 0.00;
					allpay = this.webMananger.getPayoutListDAO()
							.getAllPayoutByUser(user.getAid());
					// 总收益利息
					Double incomePro = 0.00;
					incomePro = this.webMananger.getProfitDAO()
							.getIncomeProfitByUser(user.getAid());
					// 总支出利息
					Double payPro = 0.00;
					payPro = this.webMananger.getProfitDAO()
							.getPayProfitByUser(user.getAid());
					// 现有利息
					Double nowPro = incomePro - payPro;

					// 当前余额（本金）
					Double balance = allcome - allpay;
					if (balance > 0) {
						Profit inn = new Profit();
						Paytype tt = new Paytype();
						inn.setImoney(balance * rate.getRate());
						System.out.println("任务执行完毕:" + rate.getRate());
						tt.setPid(5);
						String desc = String.format("%s利息结算", DateUtils
								.dateToString(new Date(), "yyyy年MM月dd日"));

						inn.setAccount(user);
						inn.setIdesc(desc);
						inn.setItime(new Date());
						inn.setPaytype(tt);
						inn.setSuccess(isSuccess);
						inn.setSuccessTime(new Date());

						if (user.getComId() != null) {
							inn.setComId(user.getComId());
						}

						this.webMananger.getProfitDAO().save(inn);
						System.out.println("任务执行完毕:" + inn.getIdesc());
					}

				}

			}
		}

		System.out.println("任务执行完毕:");
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/ComPanyList")
	@ResponseBody
	public Map ComPanyList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "contentId", required = false) Integer contentId,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		if (type == 1) {
			ll = this.webMananger.getCompanyDAO().findAll();
		} else if (type == 2) {
			Company com = this.webMananger.getCompanyDAO().findById(contentId);
			ll = this.webMananger.getSubCompanyDAO().findByProperty("company",
					com);
			for (Object cc : ll) {

				((Subcompany) cc).setCnid(com.getCid() + "");
				((Subcompany) cc).setCname(com.getCname());
			}

		} else if (type == 3) {
			Subcompany sub = this.webMananger.getSubCompanyDAO().findById(
					contentId);

			ll = this.webMananger.getDepartmentDAO().findByProperty(
					"subcompany", sub);
			/*
			 * Department dep = this.webMananger.getDepartmentDAO().findById(
			 * contentId);
			 * 
			 * ll =
			 * this.webMananger.getPositionDAO().findByProperty("department",
			 * dep);
			 */
		} else if (type == 4) {
			Department dep = this.webMananger.getDepartmentDAO().findById(
					contentId);

			ll = this.webMananger.getPositionDAO().findByProperty("department",
					dep);
		} else {
			Position pos = this.webMananger.getPositionDAO()
					.findById(contentId);
			ll = this.webMananger.getAccountDAO().findByProperty("position",
					pos);
		}

		this.result.put("draw", draw);
		this.result.put("recordsTotal", ll.size());
		this.result.put("recordsFiltered", ll.size());
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/CompanyInstituteList")
	@ResponseBody
	public Map CompanyInstituteList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		// 获取管理员身份
		Admin admin = (Admin) session.getAttribute("admin");

		List ll = new ArrayList();
		Integer size = 0;
		ll = this.webMananger.getCompanyDAO().findAll();

		List items = new ArrayList();
		List sz = null;
		Map mm = null;
		for (int i = 0; i < ll.size(); i++) {
			Company cc = (Company) ll.get(i);

			sz = new ArrayList();
			sz.add("" + cc.getSubcompanies().size() + "");

			mm = new HashMap();
			mm.put("text", cc.getCname());
			mm.put("tags", sz);
			mm.put("Id", cc.getCid());
			mm.put("selected", false);
			mm.put("href", "actionTo('" + cc.getCid() + "','2')");

			// 子公司
			if (cc.getSubcompanies().size() > 0) {
				List sub_items = new ArrayList();
				List sbs = null;
				Map msub = null;
				Object[] objs = cc.getSubcompanies().toArray();
				for (int j = 0; j < objs.length; j++) {
					Subcompany scc = (Subcompany) objs[j];
					if (admin.getSubcompany() != null) {
						if (admin.getSubcompany().getSid() == scc.getSid()) {
							sbs = new ArrayList();
							sbs.add("" + scc.getDepartments().size() + "");

							msub = new HashMap();
							msub.put("text", scc.getSname());
							msub.put("Id", scc.getSid());
							msub.put("tags", sbs);
							msub.put("href", "actionTo('" + scc.getSid()
									+ "','3')");
							sub_items.add(msub);
							// 子部门
							if (scc.getDepartments().size() > 0) {
								List dep_items = new ArrayList();
								List deps = null;
								Map depmm = null;
								Object[] objss = scc.getDepartments().toArray();
								for (int z = 0; z < objss.length; z++) {
									Department departments = (Department) objss[z];

									deps = new ArrayList();
									deps.add(""
											+ departments.getPositions().size()
											+ "");

									depmm = new HashMap();
									depmm.put("text", departments.getDname());
									depmm.put("href", "actionTo('"
											+ departments.getDid() + "','4')");
									depmm.put("tags", deps);
									depmm.put("Id", departments.getDid());
									dep_items.add(depmm);

									// 职位
									if (departments.getPositions().size() > 0) {
										List pos_items = new ArrayList();
										List poss = null;
										Map posmm = null;
										Object[] objpos = departments
												.getPositions().toArray();
										for (int x = 0; x < objpos.length; x++) {
											Position position = (Position) objpos[x];

											poss = new ArrayList();
											poss.add(""
													+ position.getAccounts()
															.size() + "");

											posmm = new HashMap();
											posmm.put("text",
													position.getPname());
											posmm.put("href", "actionTo('"
													+ position.getPid()
													+ "','5')");
											posmm.put("Id", position.getPid());
											posmm.put("tags", poss);
											pos_items.add(posmm);
										}
										depmm.put("nodes", pos_items);
									}

								}
								msub.put("nodes", dep_items);
							}

							break;
						}
					} else {
						sbs = new ArrayList();
						sbs.add("" + scc.getDepartments().size() + "");

						msub = new HashMap();
						msub.put("text", scc.getSname());
						msub.put("Id", scc.getSid());
						msub.put("tags", sbs);
						msub.put("href", "actionTo('" + scc.getSid() + "','3')");
						sub_items.add(msub);
						// 子部门
						if (scc.getDepartments().size() > 0) {
							List dep_items = new ArrayList();
							List deps = null;
							Map depmm = null;
							Object[] objss = scc.getDepartments().toArray();
							for (int z = 0; z < objss.length; z++) {
								Department departments = (Department) objss[z];

								deps = new ArrayList();
								deps.add("" + departments.getPositions().size()
										+ "");

								depmm = new HashMap();
								depmm.put("text", departments.getDname());
								depmm.put("href",
										"actionTo('" + departments.getDid()
												+ "','4')");
								depmm.put("tags", deps);
								depmm.put("Id", departments.getDid());
								dep_items.add(depmm);

								// 职位
								if (departments.getPositions().size() > 0) {
									List pos_items = new ArrayList();
									List poss = null;
									Map posmm = null;
									Object[] objpos = departments
											.getPositions().toArray();
									for (int x = 0; x < objpos.length; x++) {
										Position position = (Position) objpos[x];

										poss = new ArrayList();
										poss.add(""
												+ position.getAccounts().size()
												+ "");

										posmm = new HashMap();
										posmm.put("text", position.getPname());
										posmm.put("href", "actionTo('"
												+ position.getPid() + "','5')");
										posmm.put("Id", position.getPid());
										posmm.put("tags", poss);
										pos_items.add(posmm);
									}
									depmm.put("nodes", pos_items);
								}

							}
							msub.put("nodes", dep_items);
						}
					}

				}

				mm.put("nodes", sub_items);
			}

			items.add(mm);

		}

		this.result.put("success", true);
		this.result.put("recordsTotal", ll.size());
		this.result.put("recordsFiltered", ll.size());
		this.result.put("data", items);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveCompany")
	@ResponseBody
	public Map getProfitDetail(ModelMap map, HttpSession session, Integer type,
			Integer contentId, Company com, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Company inn = null;
		if (contentId != null) {
			inn = this.webMananger.getCompanyDAO().findById(contentId);
			inn.setCdesc(com.getCdesc());
			inn.setCname(com.getCname());

			this.webMananger.getCompanyDAO().saveOrUpdate(inn);
		} else {

			this.webMananger.getCompanyDAO().save(com);
		}

		this.result.put("href", "actionTo('" + com.getCid() + "','2')");
		this.result.put("name", com.getCname());
		this.result.put("Id", com.getCid());
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveSubCompany")
	@ResponseBody
	public Map saveSubCompany(ModelMap map, HttpSession session, Integer type,
			Integer contentId, Subcompany com, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Subcompany inn = null;
		Company cc = this.webMananger.getCompanyDAO().findById(contentId);
		if (com.getSid() != null) {
			inn = this.webMananger.getSubCompanyDAO().findById(com.getSid());
			inn.setSdesc(com.getSdesc());
			inn.setSname(com.getSname());
			inn.setCompany(cc);

			this.webMananger.getSubCompanyDAO().saveOrUpdate(inn);
		} else {

			com.setCompany(cc);
			this.webMananger.getSubCompanyDAO().save(com);
		}
		this.result.put("href", "actionTo('" + com.getSid() + "','3')");
		this.result.put("name", com.getSname());
		this.result.put("Id", com.getSid());
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveDepartment")
	@ResponseBody
	public Map saveSubCompany(ModelMap map, HttpSession session, Integer type,
			Integer contentId, Department com, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Department inn = null;
		Subcompany cc = this.webMananger.getSubCompanyDAO().findById(contentId);
		if (com.getDid() != null) {
			inn = this.webMananger.getDepartmentDAO().findById(com.getDid());
			inn.setDdesc(com.getDdesc());
			inn.setDname(com.getDname());
			inn.setSubcompany(cc);

			this.webMananger.getDepartmentDAO().saveOrUpdate(inn);
		} else {

			com.setSubcompany(cc);
			this.webMananger.getDepartmentDAO().save(com);
		}
		this.result.put("href", "actionTo('" + com.getDid() + "','4')");
		this.result.put("name", com.getDname());
		this.result.put("Id", com.getDid());
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/savePosition")
	@ResponseBody
	public Map savePosition(ModelMap map, HttpSession session, Integer type,
			Integer contentId, Position com, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Position inn = null;
		Department cc = this.webMananger.getDepartmentDAO().findById(contentId);

		if (com.getPid() != null) {
			inn = this.webMananger.getPositionDAO().findById(com.getPid());
			inn.setPdesc(com.getPdesc());
			inn.setPname(com.getPname());
			inn.setDepartment(cc);

			this.webMananger.getPositionDAO().saveOrUpdate(inn);
		} else {

			com.setDepartment(cc);
			this.webMananger.getPositionDAO().save(com);
		}
		this.result.put("href", "actionTo('" + com.getPid() + "','5')");
		this.result.put("name", com.getPname());
		this.result.put("Id", com.getPid());
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/savePositionUser")
	@ResponseBody
	public Map savePositionUser(ModelMap map, HttpSession session,
			Integer type,
			@RequestParam(value = "userId", required = false) Integer[] aids,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Account inn = null;
		Position cc = this.webMananger.getPositionDAO().findById(contentId);
		Admin admin = (Admin) session.getAttribute("admin");
		for (Integer aid : aids) {
			if (aid != null) {
				inn = this.webMananger.getAccountDAO().findById(aid);
				inn.setPosition(cc);

				if (admin.getSubcompany() != null) {
					inn.setComId(admin.getSubcompany().getSid());

					// 银行卡
					List<Bankcard> cars = this.webMananger.getBankCardDAO()
							.findByProperty("account", inn);
					for (Bankcard bankcard : cars) {
						if (admin.getSubcompany() != null) {
							bankcard.setComId(admin.getSubcompany().getSid());
						}

						this.webMananger.getBankCardDAO()
								.saveOrUpdate(bankcard);
					}
					// 工资
					List<Wages> wages = this.webMananger.getWagesDAO()
							.findByProperty("account", inn);
					for (Wages wage : wages) {
						if (admin.getSubcompany() != null) {
							wage.setComId(admin.getSubcompany().getSid());
							this.webMananger.getWagesDAO().saveOrUpdate(wage);
						}

					}
					// 收入
					List<Incomelist> incomlist = this.webMananger
							.getIncomeListDAO().findByProperty("account", inn);
					for (Incomelist income : incomlist) {
						if (admin.getSubcompany() != null) {
							income.setComId(admin.getSubcompany().getSid());
						}

						this.webMananger.getIncomeListDAO()
								.saveOrUpdate(income);
					}
					// 支出
					List<Payoutlist> payoutlist = this.webMananger
							.getPayoutListDAO().findByProperty("account", inn);
					for (Payoutlist payout : payoutlist) {
						if (admin.getSubcompany() != null) {
							payout.setComId(admin.getSubcompany().getSid());
						}

						this.webMananger.getPayoutListDAO()
								.saveOrUpdate(payout);
					}
					// 利息
					List<Profit> profits = this.webMananger.getProfitDAO()
							.findByProperty("account", inn);
					for (Profit profit : profits) {
						if (admin.getSubcompany() != null) {
							profit.setComId(admin.getSubcompany().getSid());
						}

						this.webMananger.getProfitDAO().saveOrUpdate(profit);
					}
				}

				this.webMananger.getAccountDAO().saveOrUpdate(inn);
			}
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveUserAccount")
	@ResponseBody
	public Map saveUserAccount(ModelMap map, HttpSession session,
			Account account, Integer posId, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Account inn = null;
		Position cc = null;

		Admin admin = (Admin) session.getAttribute("admin");
		if (posId != null) {
			cc = this.webMananger.getPositionDAO().findById(posId);
		}
		if (account.getAid() != null) {
			inn = this.webMananger.getAccountDAO().findById(account.getAid());
			if (cc != null) {
				inn.setPosition(cc);
			}
			inn.setName(account.getName());
			inn.setBirth(account.getBirth());
			inn.setImg(account.getImg());
			inn.setIsjob(account.getIsjob());
			inn.setSex(account.getSex());
			inn.setTel(account.getTel());
			inn.setIdentityCard(account.getIdentityCard());
			if (admin.getSubcompany() != null) {
				inn.setComId(admin.getSubcompany().getSid());
			}

			this.webMananger.getAccountDAO().saveOrUpdate(inn);
		} else {
			if (cc != null) {
				account.setPosition(cc);
			}
			account.setCreatetime(new Date());
			if (admin.getSubcompany() != null) {
				account.setComId(admin.getSubcompany().getSid());
			}
			this.webMananger.getAccountDAO().save(account);

		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveBankCard")
	@ResponseBody
	public Map saveBankCard(ModelMap map, HttpSession session,
			Bankcard account, Integer aid, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Bankcard inn = null;
		Account cc = null;
		Admin admin = (Admin) session.getAttribute("admin");
		if (aid != null) {
			cc = this.webMananger.getAccountDAO().findById(aid);
		}
		if (account.getBid() != null) {
			inn = this.webMananger.getBankCardDAO().findById(account.getBid());
			if (cc != null) {
				inn.setAccount(cc);
			}
			inn.setBname(account.getBname());
			inn.setCardNo(account.getCardNo());
			if (admin.getSubcompany() != null) {
				inn.setComId(admin.getSubcompany().getSid());
			}

			this.webMananger.getBankCardDAO().saveOrUpdate(inn);
		} else {
			// 是否已绑定卡
			List<Bankcard> cards = this.webMananger.getBankCardDAO()
					.findByProperty("account", cc);
			if (cards != null && cards.size() > 0) {
				inn = cards.get(0);
				if (cc != null) {
					inn.setAccount(cc);
				}
				inn.setBname(account.getBname());
				inn.setCardNo(account.getCardNo());
				if (admin.getSubcompany() != null) {
					inn.setComId(admin.getSubcompany().getSid());
				}
				this.webMananger.getBankCardDAO().saveOrUpdate(inn);
			} else {
				if (cc != null) {
					account.setAccount(cc);
				}
				this.webMananger.getBankCardDAO().save(account);
			}
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/***
	 * 保存用户工资
	 * 
	 * @param map
	 * @param session
	 * @param account
	 * @param aid
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/manager/saveUserWages")
	@ResponseBody
	public Map saveUserWages(ModelMap map, HttpSession session, Wages account,
			Integer aid, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Wages inn = null;
		Account cc = null;
		Admin admin = (Admin) session.getAttribute("admin");
		if (aid != null) {
			cc = this.webMananger.getAccountDAO().findById(aid);
		}
		if (account.getWid() != null) {
			inn = this.webMananger.getWagesDAO().findById(account.getWid());
			if (cc != null) {
				inn.setAccount(cc);
			}
			inn.setWnum(account.getWnum());
			inn.setWdesc(account.getWdesc());
			inn.setWtime(new Date());
			inn.setEtr("");
			if (inn.getAccount().getComId() != null) {
				inn.setComId(inn.getAccount().getComId());
			}
			this.webMananger.getWagesDAO().saveOrUpdate(inn);
		} else {
			inn = new Wages();
			if (cc != null) {
				inn.setAccount(cc);
			}
			inn.setWnum(account.getWnum());
			inn.setWdesc(account.getWdesc());
			inn.setWtime(new Date());
			inn.setStatus(0);
			inn.setEtr("");
			if (inn.getAccount().getComId() != null) {
				inn.setComId(inn.getAccount().getComId());
			}

			this.webMananger.getWagesDAO().save(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveRate")
	@ResponseBody
	public Map saveRate(ModelMap map, HttpSession session, Rate account,
			Integer aid, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (account.getIsUse() == 1) {
			List<Rate> ll = this.webMananger.getRateDAO().findAll();
			for (Rate r : ll) {
				if (r.getIsUse() != null && r.getIsUse() == (short) 1) {
					r.setIsUse((short) 0);

					this.webMananger.getRateDAO().saveOrUpdate(r);
				}
			}
		}

		Rate inn = null;
		if (account.getRid() != null) {
			inn = this.webMananger.getRateDAO().findById(account.getRid());
			inn.setRate(account.getRate());
			inn.setIsUse(account.getIsUse());
			inn.setChangeTime(new Date());
			inn.setRname(account.getRname());
			this.webMananger.getRateDAO().saveOrUpdate(inn);
		} else {
			account.setCreatTime(new Date());
			this.webMananger.getRateDAO().save(account);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/comPanyDetail")
	@ResponseBody
	public Map getComPanyDetail(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Company inn = this.webMananger.getCompanyDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/subCompanyDetail")
	@ResponseBody
	public Map getSubCompanyDetail(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Subcompany inn = this.webMananger.getSubCompanyDAO().findById(
					contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/departmentDetail")
	@ResponseBody
	public Map departmentDetail(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Department inn = this.webMananger.getDepartmentDAO().findById(
					contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/positionDetail")
	@ResponseBody
	public Map positionDetail(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Position inn = this.webMananger.getPositionDAO()
					.findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteUserAccount")
	@ResponseBody
	public Map deleteUserAccount(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Account inn = this.webMananger.getAccountDAO().findById(contentId);
			List<Profit> ll = this.webMananger.getProfitDAO().findByProperty(
					"account", inn);
			for (Profit pf : ll) {
				this.webMananger.getProfitDAO().delete(pf);
			}
			this.webMananger.getAccountDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteUserIncome")
	@ResponseBody
	public Map deleteUserIncome(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Incomelist income = this.webMananger.getIncomeListDAO().findById(
					contentId);
			this.webMananger.getIncomeListDAO().delete(income);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteBankCard")
	@ResponseBody
	public Map deleteBankCard(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Bankcard inn = this.webMananger.getBankCardDAO()
					.findById(contentId);
			this.webMananger.getBankCardDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteRate")
	@ResponseBody
	public Map deleteRate(ModelMap map, HttpSession session, Integer contentId,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Rate inn = this.webMananger.getRateDAO().findById(contentId);
			this.webMananger.getRateDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteUserWages")
	@ResponseBody
	public Map deleteUserWages(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Wages inn = this.webMananger.getWagesDAO().findById(contentId);
			this.webMananger.getWagesDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteCompany")
	@ResponseBody
	public Map deleteCompany(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Company inn = this.webMananger.getCompanyDAO().findById(contentId);
			for (Subcompany sb : inn.getSubcompanies()) {
				for (Department dp : sb.getDepartments()) {
					for (Position ps : dp.getPositions()) {
						for (Account ac : ps.getAccounts()) {
							ac.setPosition(null);
							this.webMananger.getAccountDAO().saveOrUpdate(ac);
						}
						ps.setAccounts(null);
						this.webMananger.getPositionDAO().saveOrUpdate(ps);
					}
				}
			}
			this.webMananger.getCompanyDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteSubCompany")
	@ResponseBody
	public Map deleteSubCompany(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Subcompany inn = this.webMananger.getSubCompanyDAO().findById(
					contentId);
			for (Department dp : inn.getDepartments()) {
				for (Position ps : dp.getPositions()) {
					for (Account ac : ps.getAccounts()) {
						ac.setPosition(null);
						this.webMananger.getAccountDAO().saveOrUpdate(ac);
					}
					ps.setAccounts(null);
					this.webMananger.getPositionDAO().saveOrUpdate(ps);
				}
			}
			this.webMananger.getSubCompanyDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteDepartment")
	@ResponseBody
	public Map deleteDepartment(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Department inn = this.webMananger.getDepartmentDAO().findById(
					contentId);
			for (Position ps : inn.getPositions()) {
				for (Account ac : ps.getAccounts()) {
					ac.setPosition(null);
					this.webMananger.getAccountDAO().saveOrUpdate(ac);
				}
				ps.setAccounts(null);
				this.webMananger.getPositionDAO().saveOrUpdate(ps);
			}
			this.webMananger.getDepartmentDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deletePosition")
	@ResponseBody
	public Map deletePosition(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Position inn = this.webMananger.getPositionDAO()
					.findById(contentId);
			for (Account ac : inn.getAccounts()) {
				ac.setPosition(null);
				this.webMananger.getAccountDAO().saveOrUpdate(ac);
			}
			inn.setAccounts(null);
			this.webMananger.getPositionDAO().saveOrUpdate(inn);
			this.webMananger.getPositionDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteAccountPosition")
	@ResponseBody
	public Map deleteAccountPosition(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Admin admin = (Admin) session.getAttribute("admin");
		if (contentId != null) {
			Account inn = this.webMananger.getAccountDAO().findById(contentId);
			inn.setPosition(null);
			this.webMananger.getAccountDAO().saveOrUpdate(inn);
			;

			if (admin.getSubcompany() != null) {
				inn.setComId(null);

				// 银行卡
				List<Bankcard> cars = this.webMananger.getBankCardDAO()
						.findByProperty("account", inn);
				for (Bankcard bankcard : cars) {
					bankcard.setComId(null);

					this.webMananger.getBankCardDAO().saveOrUpdate(bankcard);
				}
				// 工资
				List<Wages> wages = this.webMananger.getWagesDAO()
						.findByProperty("account", inn);
				for (Wages wage : wages) {
					wage.setComId(null);

					this.webMananger.getWagesDAO().saveOrUpdate(wage);
				}
				// 收入
				List<Incomelist> incomlist = this.webMananger
						.getIncomeListDAO().findByProperty("account", inn);
				for (Incomelist income : incomlist) {
					income.setComId(null);
					this.webMananger.getIncomeListDAO().saveOrUpdate(income);
				}
				// 支出
				List<Payoutlist> payoutlist = this.webMananger
						.getPayoutListDAO().findByProperty("account", inn);
				for (Payoutlist payout : payoutlist) {
					payout.setComId(null);
					this.webMananger.getPayoutListDAO().saveOrUpdate(payout);
				}
				// 利息
				List<Profit> profits = this.webMananger.getProfitDAO()
						.findByProperty("account", inn);
				for (Profit profit : profits) {
					profit.setComId(null);
					this.webMananger.getProfitDAO().saveOrUpdate(profit);
				}
			}
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/************************************************************* 用户管理 **********************************************************************************/
	@RequestMapping(value = "/manager/BankCardList")
	@ResponseBody
	public Map BankCardList(
			ModelMap map,
			HttpSession session,

			@RequestParam(value = "type", required = false) Integer type,

			@RequestParam(value = "draw", required = false) Integer draw,

			@RequestParam(value = "start", required = false) Integer start,

			@RequestParam(value = "length", required = false) Integer length,

			@RequestParam(value = "search", required = false) String search,
			@RequestParam(value = "search[value]", required = false) String value,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Admin admin = (Admin) session.getAttribute("admin");
		List ll = new ArrayList();
		Integer size = 0;
		if (admin.getSubcompany() != null) {
			size = this.webMananger.getBankCardDAO().countAll("comId",
					admin.getSubcompany().getSid());
			ll = this.webMananger.getBankCardDAO().findByPage(start, length,
					"comId", admin.getSubcompany().getSid());
		} else {
			size = this.webMananger.getBankCardDAO().countAll();
			ll = this.webMananger.getBankCardDAO().findByPage(start, length);
		}

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/rateList")
	@ResponseBody
	public Map rateList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		size = this.webMananger.getRateDAO().countAll();
		ll = this.webMananger.getRateDAO().findByPage(start, length);

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/***
	 * 工资列表
	 * 
	 * @param map
	 * @param session
	 * @param type
	 *            1：未发放工资 其他：所有工资
	 * @param draw
	 * @param start
	 * @param length
	 * @param value
	 *            搜索key
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/manager/UserWagesList")
	@ResponseBody
	public Map UserWagesList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search[value]", required = false) String value,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Admin admin = (Admin) session.getAttribute("admin");
		List ll = new ArrayList();
		Integer size = 0;
		if (type == 1) {
			if (value != null && !value.equalsIgnoreCase("")) {
				// 先查用户
				List<Account> users = this.webMananger.getAccountDAO()
						.findByProPage(start, size, "name", value);
				for (Account account : users) {
					List<Wages> wages = this.webMananger.getWagesDAO()
							.findByStatusProperty("account", account, 0);
					for (Wages wage : wages) {
						ll.add(wage);
					}
				}

				size = ll.size();
			} else {
				if (admin.getSubcompany() != null) {
					Map par = new HashMap();
					par.put("status", "0");
					par.put("comId", admin.getSubcompany().getSid());
					size = this.webMananger.getWagesDAO().countByProAll(par,
							"etr", "");
					ll = this.webMananger.getWagesDAO().findByProPage(par,
							start, length, "etr", "");
				} else {
					Map par = new HashMap();
					par.put("status", "0");
					size = this.webMananger.getWagesDAO().countByProAll(par,
							"etr", "");
					ll = this.webMananger.getWagesDAO().findByProPage(par,
							start, length, "etr", "");
				}
			}

		} else {
			if (admin.getSubcompany() != null) {
				size = this.webMananger.getWagesDAO().countAll("comId",
						admin.getSubcompany().getSid());
				ll = this.webMananger.getWagesDAO().findByPage(start, length,
						"comId", admin.getSubcompany().getSid());
			} else {
				size = this.webMananger.getWagesDAO().countAll();
				ll = this.webMananger.getWagesDAO().findByPage(start, length);
			}
		}

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/***
	 * 用户收入管理
	 * 
	 * @param map
	 * @param session
	 * @param type
	 * @param draw
	 * @param start
	 * @param length
	 * @param search
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/manager/IncomeList")
	@ResponseBody
	public Map IncomeList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		Admin admin = (Admin) session.getAttribute("admin");
		if (admin.getSubcompany() != null) {
			size = this.webMananger.getIncomeListDAO().countAll("comId",
					admin.getSubcompany().getSid());
			ll = this.webMananger.getIncomeListDAO().findByPage(start, length,
					"comId", admin.getSubcompany().getSid());
		} else {
			size = this.webMananger.getIncomeListDAO().countAll();
			ll = this.webMananger.getIncomeListDAO().findByPage(start, length);
		}

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/***
	 * 支出管理
	 * 
	 * @param map
	 * @param session
	 * @param type
	 * @param draw
	 * @param start
	 * @param length
	 * @param search
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value = "/manager/OutcomeList")
	@ResponseBody
	public Map OutcomeList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) short type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		Admin admin = (Admin) session.getAttribute("admin");
		if (admin.getSubcompany() != null) {
			size = this.webMananger.getPayoutListDAO().countAll("comId",
					admin.getSubcompany().getSid(), type);
			ll = this.webMananger.getPayoutListDAO().findByPage(start, length,
					"comId", admin.getSubcompany().getSid(), type);
		} else {
			size = this.webMananger.getPayoutListDAO().countAll(type);
			ll = this.webMananger.getPayoutListDAO().findByPage(start, length,
					type);
		}

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/ProfitList")
	@ResponseBody
	public Map ProfitList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) short type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		Admin admin = (Admin) session.getAttribute("admin");
		if (admin.getSubcompany() != null) {
			size = this.webMananger.getProfitDAO().countAll("comId",
					admin.getSubcompany().getSid(), type);
			ll = this.webMananger.getProfitDAO().findByPage(start, length,
					"comId", admin.getSubcompany().getSid(), type);
		} else {
			size = this.webMananger.getProfitDAO().countAll(type);
			ll = this.webMananger.getProfitDAO()
					.findByPage(start, length, type);
		}

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/AdminLogList")
	@ResponseBody
	public Map AdminLogList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		size = this.webMananger.getAdminLogDAO().countAll();
		ll = this.webMananger.getAdminLogDAO().findByPage(start, length);

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/BackupRecordList")
	@ResponseBody
	public Map BackupRecordList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		if (start == null) {
			start = 0;
		}

		if (length == null) {
			length = 10;
		}
		size = this.webMananger.getBackupRecordDAO().countAll();
		ll = this.webMananger.getBackupRecordDAO().findByPage(start, length);

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/RecoverRecordList")
	@ResponseBody
	public Map RecoverRecordList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		size = this.webMananger.getRecoverRecordDAO().countAll();
		ll = this.webMananger.getRecoverRecordDAO().findByPage(start, length);

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/BackUpDataBase")
	@ResponseBody
	public Map BackUpDataBase(ModelMap map, HttpSession session) {
		this.result = new HashMap();
		try {
			String fileName = String.format("%s.sql",
					DateUtils.formatDateTime(new Date()));
			fileName = fileName.replace(" ", "-");
			fileName = fileName.replace(":", "-");
			if (FileUtil.exportDatabaseTool(Config.STRING_MYSQL_HOST,
					Config.STRING_MYSQL_NAME, Config.STRING_MYSQL_PWD,
					Config.STRING_MYSQL_PATH, fileName, Config.STRING_MYSQL_DB)) {

				// 开始添加数据
				String path = Config.STRING_MYSQL_PATH + "/" + fileName;
				Backuprecord record = new Backuprecord();
				record.setCreateDate(new Date());
				record.setPath(path);

				this.webMananger.getBackupRecordDAO().save(record);
				System.out.println("数据库成功备份！！！");
				this.status = 200;
				this.message = "备份成功";
			} else {
				this.status = 201;
				this.message = "备份失败";
				System.out.println("数据库备份失败！！！");
			}

			return getResult();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}

		this.status = 201;
		this.message = "备份失败";

		return getResult();

	}

	@RequestMapping(value = "/manager/recoverDataBase")
	@ResponseBody
	public Map recoverDataBase(
			@RequestParam(value = "contentId", required = false) Integer contentId,
			HttpSession session) {
		Map map = new HashMap();
		// 获取记录
		if (contentId != null) {
			Backuprecord record = this.webMananger.getBackupRecordDAO()
					.findById(contentId);
			if (record != null) {
				if (FileUtil.load(record.getPath())) {
					// 添加恢复记录

					this.webMananger.getBackupRecordDAO().save(record);

					Recoverrecord re = new Recoverrecord();
					re.setRecoverDate(new Date());
					re.setBackuprecord(record);

					this.webMananger.getRecoverRecordDAO().save(re);

					this.status = 200;
					return map;
				}
			}
		}

		this.status = 201;
		return map;
	}

	/************************************************************* 用户管理 **********************************************************************************/

	/************************************************************* GIS管理 **********************************************************************************/
	/************************************************************* 上传管理 **********************************************************************************/
	@RequestMapping(value = "/manager/uploadPicture")
	public String uploadPicture(ModelMap map, HttpSession session,
			ServletRequest request, Model model) {
		return "controller";
	}

	@RequestMapping(value = "/manager/batchImportData")
	@ResponseBody
	public Map batchImportData(ModelMap map, HttpSession session, String name,
			Integer type, ServletRequest request, Model model) {
		this.result = new HashMap();
		this.status = 200;
		this.message = "导入成功";
		Map data = null;
		try {
			data = FileUtil.PoiReadFromeExcel(name);
			if (data != null) {
				Map res = excuteAddData(data, type);

				this.result.put("error", res.get("error"));
				this.result.put("totalFailC", res.get("failCount"));
				this.result.put("totalFailCC", res.get("failCCount"));
				this.result.put("successCount", res.get("successCount"));
				this.result.put("successCCount", res.get("successCCount"));
			} else {
				this.status = 201;
				this.message = "请按照正确格式上传文件!";
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		if (data == null) {
			this.status = 201;
			this.message = "请按照正确格式上传文件!";
		}

		return getResult();
	}

	private Map excuteAddData(Map resultMap, Integer type) {
		String title = resultMap.get("title").toString();
		List data = (List) resultMap.get("data");
		Map result = new HashMap();

		Integer failCount = 0;
		Integer failCCount = 0;
		Integer successCount = 0;
		Integer successCCount = 0;
		String message = "";
		List errors = new ArrayList();

		// 如果名字不符合要求
		List<Subcompany> companys = this.webMananger.getSubCompanyDAO()
				.findBySname(title);
		Map map = null;
		Account account = null;
		if ((title.equals("")) && (companys == null || companys.size() == 0)) {
			failCount = data.size();
			failCCount = data.size();
			message = "标题格式有误，请按指定格式编写！";
		} else {
			if (companys != null && companys.size() > 0) {
				Subcompany company = companys.get(0);
				if (type == 1) {
					for (int i = 0; i < data.size(); i++) {
						account = new Account();
						map = (Map) data.get(i);
						account.setName(map.get(Config.EXCEL_STRING_USER.get(1)) == null ? ""
								: map.get(Config.EXCEL_STRING_USER.get(1))
										.toString());
						Integer sex = map.get(Config.EXCEL_STRING_USER.get(2)) == null ? 1
								: (map.get(Config.EXCEL_STRING_USER.get(2))
										.toString().equalsIgnoreCase("男") ? 1
										: 0);
						account.setSex(sex);
						account.setIdentityCard(map
								.get(Config.EXCEL_STRING_USER.get(3)) == null ? ""
								: map.get(Config.EXCEL_STRING_USER.get(3))
										.toString());
						account.setCreatetime(new Date());
						account.setIsjob((short) 1);
						account.setTel(map.get(Config.EXCEL_STRING_USER.get(6)) == null ? ""
								: map.get(Config.EXCEL_STRING_USER.get(6))
										.toString());
						account.setImg(sex == 1 ? Config.STRING_BOY
								: Config.STRING_GIRL);
						account.setComId(company.getSid());

						if ((account.getName() != null && account
								.getIdentityCard() != null)
								&& (!account.getName().equals("") && !account
										.getIdentityCard().equalsIgnoreCase(""))) {
							// 排重
							List ll = this.webMananger.getAccountDAO()
									.findByProperty("identityCard",
											account.getIdentityCard());
							if (ll == null || ll.size() == 0) {
								this.webMananger.getAccountDAO().save(account);
								successCount++;
							} else {
								failCount++;
								Map errorMap = new HashMap();
								errorMap.put("name", account.getName());
								errorMap.put("identityCard",
										account.getIdentityCard());
								errors.add(errorMap);
							}

						}

						// 如果用户已经导入，查找相关用户
						if (account == null || account.getAid() == null) {
							String idCard = map.get(Config.EXCEL_STRING_USER
									.get(3)) == null ? "" : map.get(
									Config.EXCEL_STRING_USER.get(3)).toString();
							if (!idCard.equalsIgnoreCase("")) {
								List<Account> accounts = this.webMananger
										.getAccountDAO().findByProperty(
												"identityCard", idCard);
								if (accounts != null && accounts.size() > 0) {
									account = accounts.get(0);
								}
							}
						}

						// 获取用户数是否已经添加相同银行卡
						String cardNo = map
								.get(Config.EXCEL_STRING_USER.get(4)) == null ? ""
								: map.get(Config.EXCEL_STRING_USER.get(4))
										.toString();
						if (cardNo != null && !cardNo.equalsIgnoreCase("")
								&& account.getAid() != null) {
							List ll = this.webMananger.getBankCardDAO()
									.findByAccountAndCardNo(account, cardNo);
							if (ll == null || ll.size() == 0) {
								Bankcard card = new Bankcard();
								card.setAccount(account);
								card.setCardNo(cardNo);
								card.setComId(company.getSid());
								card.setBname(map.get(Config.EXCEL_STRING_USER
										.get(5)) == null ? "" : map.get(
										Config.EXCEL_STRING_USER.get(5))
										.toString());

								if (card.getCardNo() != null
										&& !card.getCardNo().equalsIgnoreCase(
												"")) {
									this.webMananger.getBankCardDAO()
											.save(card);
									successCCount++;
								} else {
									failCCount++;
								}
							} else {
								failCCount++;
								Map errorMap = new HashMap();
								errorMap.put("name", account.getName());
								errorMap.put("identityCard",
										account.getIdentityCard());
								errors.add(errorMap);
							}
						}
					}
				} else {
					for (int i = 0; i < data.size(); i++) {
						map = (Map) data.get(i);
						String identityCard = map.get(
								Config.EXCEL_STRING_USER.get(3)).toString();
						List list = this.webMananger.getAccountDAO()
								.findByProperty("identityCard", identityCard);
						if (list != null && list.size() > 0) {
							account = (Account) list.get(0);
						}

						if (account != null && account.getAid() != null) {
							Wages wage = new Wages();
							wage.setAccount(account);

							String month = map.get(Config.EXCEL_STRING_USER
									.get(8)) != null ? map.get(
									Config.EXCEL_STRING_USER.get(8)).toString()
									: DateUtils.dateToString(new Date(),
											"yyyy年MM月");
							String monthStr = month + "工资";

							// 查找工资是否添加
							List<Wages> ll = this.webMananger.getWagesDAO()
									.findByAccountAndMonth(account, monthStr);
							if (ll != null && ll.size() > 0) {
								for (Wages wages : ll) {
									this.webMananger.getWagesDAO()
											.delete(wages);
								}
							}

							if (map.get(Config.EXCEL_STRING_USER.get(7)) != null
									&& map.get(Config.EXCEL_STRING_USER.get(7)) != "") {
								Double num = Double.valueOf(map.get(
										Config.EXCEL_STRING_USER.get(7))
										.toString());
								wage.setWnum(num);
							}

							wage.setWdesc(monthStr);
							wage.setEtr("");
							wage.setWtime(new Date());
							wage.setStatus(0);
							wage.setComId(company.getSid());

							this.webMananger.getWagesDAO().save(wage);
							successCount++;
						} else {
							failCount++;
							Map errorMap = new HashMap();
							errorMap.put("account", account);
							errors.add(errorMap);
						}

					}
				}
			}

		}

		result.put("error", errors);
		result.put("failCount", failCount);
		result.put("failCCount", failCCount);
		result.put("successCount", successCount);
		result.put("successCCount", successCCount);
		return result;

	}

	@RequestMapping(value = "/manager/fileUpload")
	@ResponseBody
	public Map fileUpload(ModelMap map, HttpSession session,

	@RequestParam(value = "file", required = false) MultipartFile[] files,
			ServletRequest request, Model model) {
		this.result = new HashMap();
		// 保存图片
		String fileName = "";
		String result = "";
		if (files != null && files.length > 0) {

			MultipartFile file = null;
			Set items = new HashSet();
			for (int i = 0; i < files.length; i++) {
				if (files[i] != null) {
					file = files[i];
					fileName = String.format(
							Config.STRING_USER_FEELING_PICTUREA_FORMAT,
							new Date().getTime(), i);
					result = FileUtil.savePicture(file, fileName,
							"upload/uploadImages/");
					if (!result.equals("")) {
						fileName = Config.STRING_SYSTEM_ADDRESS
								+ "upload/uploadImages/" + result;
					} else {
						fileName = "";
					}

				}
			}
			this.result.put("fileName", fileName);
		}
		this.result.put("code", 200);
		return getResult();
	}

	@RequestMapping(value = "/manager/excelfileUpload")
	@ResponseBody
	public Map excelfileUpload(ModelMap map, HttpSession session,

	@RequestParam(value = "file", required = false) MultipartFile[] files,
			ServletRequest request, Model model) {
		this.result = new HashMap();
		// 保存图片
		String fileName = "";
		String result = "";
		if (files != null && files.length > 0) {

			MultipartFile file = null;
			Set items = new HashSet();
			for (int i = 0; i < files.length; i++) {
				if (files[i] != null) {
					file = files[i];
					fileName = String.format(
							Config.STRING_USER_FEELING_PICTUREA_FORMAT,
							new Date().getTime(), i);
					result = FileUtil.savePicture(file, fileName,
							"upload/files/");
					if (!result.equals("")) {
						fileName = Config.STRING_SYSTEM_ADDRESS
								+ "upload/files/" + result;
					} else {
						fileName = "";
					}

				}
			}
			this.result.put("fileName", fileName);
		}
		this.result.put("code", 200);
		return getResult();
	}

	// ************************************************************* 上传管理
	// **********************************************************************************/

	@RequestMapping(value = "/manager/menuList")
	@ResponseBody
	public Map menuList(ModelMap map, HttpSession session,
			@RequestParam(value = "type", required = false) Integer type,
			@RequestParam(value = "draw", required = false) Integer draw,
			@RequestParam(value = "start", required = false) Integer start,
			@RequestParam(value = "length", required = false) Integer length,
			@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		// List ll = new ArrayList();
		// ll = this.webMananger.getMenuDAO().findAll();

		List<UserRole> ll = new ArrayList();
		Integer adminId = (Integer) session.getAttribute("adminId");
		if (adminId == null) {
			adminId = 1;
		}

		Admin admin = this.webMananger.getAdminDAO().findById(adminId);
		if (admin != null) {
			ll = this.webMananger.getUserRoleDAO().findByProperty("roleType",
					admin.getRoleType());
		}

		List<Map> result = new ArrayList();
		Map item = null;
		for (UserRole role : ll) {
			boolean isNew = true;
			if (result.size() == 0) {
				item = new HashMap();
				item.put("menu", role.getSubMenu().getMenu());

				if (item.get("submenus") == null) {
					item.put("submenus", new ArrayList());
				}

				List submenus = (List) item.get("submenus");
				submenus.add(role.getSubMenu());

				item.put("submenus", submenus);

				role.getSubMenu().setMenu(null);
				result.add(item);

			} else {
				int count = 0;
				for (int i = 0; i < result.size(); i++) {
					Map m = result.get(i);
					Menu menu = (Menu) m.get("menu");
					if (menu != null) {
						if (menu.getName().equalsIgnoreCase(
								role.getSubMenu().getMenu().getName())) {
							isNew = false;
							item = m;
							count = i;
							break;
						} else {

							isNew = true;
							// System.out.println("menu equal:"+role.getSubMenu().getMenu().getName()+"=="+menu.getName());
						}
					} else {
						isNew = true;
					}
				}

				if (isNew) {
					// System.out.println("menu equal:"+role.getSubMenu().getMenu().getName());
					item = new HashMap();
					item.put("menu", role.getSubMenu().getMenu());
				}

				if (item.get("submenus") == null) {
					item.put("submenus", new ArrayList());
				}

				List submenus = (List) item.get("submenus");
				if (!submenus.contains(role.getSubMenu())) {
					submenus.add(role.getSubMenu());
				}

				item.put("submenus", submenus);

				if (isNew) {
					result.add(item);
				} else {
					result.set(count, item);
				}

				role.getSubMenu().setMenu(null);
			}

		}

		// 排序
		List<Menu> menus = this.webMananger.getMenuDAO().findAll();
		List list = new ArrayList();
		for (int j = 0; j < menus.size(); j++) {
			for (int i = 0; i < result.size(); i++) {
				Map m = result.get(i);
				Menu menu = (Menu) m.get("menu");
				Menu it = menus.get(j);
				if (menu.getMenuId() == it.getMenuId()) {
					list.add(m);
				}
			}
		}

		admin.setLoginpwd(null);
		admin.getRoleType().setUserRoles(null);

		this.result.put("draw", draw);
		this.result.put("data", list);
		this.result.put("admin", admin);
		this.result.put("error", "");
		this.result.put("success", true);

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/menuItemList")
	@ResponseBody
	public Map menuItemList(
			ModelMap map,
			HttpSession session,
			@RequestParam(value = "type", required = false) Integer type,
			@RequestParam(value = "contentId", required = false) Integer contentId,
			@RequestParam(value = "draw", required = false) Integer draw,
			@RequestParam(value = "start", required = false) Integer start,
			@RequestParam(value = "length", required = false) Integer length,
			@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		List ll = new ArrayList();
		if (type == 1) {
			ll = this.webMananger.getMenuDAO().findAll();
		} else {
			if (contentId != null) {
				Menu menu = this.webMananger.getMenuDAO().findById(contentId);
				ll = this.webMananger.getSubMenuDAO().findByProperty("menu",
						menu);
			} else {
				ll = this.webMananger.getSubMenuDAO().findAll();
			}
		}

		this.result.put("draw", draw);
		this.result.put("data", ll);
		this.result.put("recordsTotal", ll.size());
		this.result.put("recordsFiltered", ll.size());
		this.result.put("error", "");
		this.result.put("success", true);

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/adminUserList")
	@ResponseBody
	public Map adminUserList(ModelMap map, HttpSession session,
			@RequestParam(value = "type", required = false) Integer type,
			@RequestParam(value = "draw", required = false) Integer draw,
			@RequestParam(value = "start", required = false) Integer start,
			@RequestParam(value = "length", required = false) Integer length,
			@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Admin admin = (Admin) session.getAttribute("admin");
		List ll = new ArrayList();
		Integer size = 0;
		if (admin.getSubcompany() != null) {
			size = this.webMananger.getAdminDAO().countAll("comId",
					admin.getSubcompany().getSid());
			ll = this.webMananger.getAdminDAO().findByPage(start, length,
					"comId", admin.getSubcompany().getSid());
		} else {
			size = this.webMananger.getAdminDAO().countAll();
			ll = this.webMananger.getAdminDAO().findByPage(start, length);
		}

		this.result.put("draw", draw);
		this.result.put("data", ll);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("error", "");
		this.result.put("success", true);

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/RoleList")
	@ResponseBody
	public Map RoleList(ModelMap map, HttpSession session,
			@RequestParam(value = "type", required = false) Integer type,
			@RequestParam(value = "draw", required = false) Integer draw,
			@RequestParam(value = "start", required = false) Integer start,
			@RequestParam(value = "length", required = false) Integer length,
			@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (start == null) {
			start = 0;
		}

		if (length == null) {
			length = 10000;
		}
		List<RoleType> ll = new ArrayList();

		Integer size = 0;
		size = this.webMananger.getRoleTypeDAO().countAll();
		ll = this.webMananger.getRoleTypeDAO().findByPage(start, length);

		this.result.put("draw", draw);
		this.result.put("data", ll);
		this.result.put("recordsTotal", ll.size());
		this.result.put("recordsFiltered", ll.size());
		this.result.put("error", "");
		this.result.put("success", true);

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/RoleByFuncList")
	@ResponseBody
	public Map RoleByFuncList(
			ModelMap map,
			HttpSession session,
			@RequestParam(value = "type", required = false) Integer type,
			@RequestParam(value = "contentId", required = false) Integer contentId,
			@RequestParam(value = "draw", required = false) Integer draw,
			@RequestParam(value = "start", required = false) Integer start,
			@RequestParam(value = "length", required = false) Integer length,
			@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		List<RoleType> ll = new ArrayList();

		if (contentId != null) {
			SubMenu subMenu = this.webMananger.getSubMenuDAO().findById(
					contentId);
			List<UserRole> userRoles = this.webMananger.getUserRoleDAO()
					.findByProperty("subMenu", subMenu);
			for (UserRole role : userRoles) {
				role.getRoleType().setAdmins(null);
				role.getRoleType().setUserRoles(null);
				ll.add(role.getRoleType());
			}
		}

		// Integer size = 0;
		// size = this.webMananger.getRoleTypeDAO().countAll();
		// ll = this.webMananger.getRoleTypeDAO().findByPage(start, length);

		this.result.put("draw", draw);
		this.result.put("data", ll);
		this.result.put("recordsTotal", ll.size());
		this.result.put("recordsFiltered", ll.size());
		this.result.put("error", "");
		this.result.put("success", true);

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/funcAuthorityList")
	@ResponseBody
	public Map funcAuthorityList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		ll = this.webMananger.getMenuDAO().findAll();

		List items = new ArrayList();
		List sz = null;
		Map mm = null;
		for (int i = 0; i < ll.size(); i++) {
			Menu cc = (Menu) ll.get(i);

			sz = new ArrayList();
			List<SubMenu> submenus = this.webMananger.getSubMenuDAO()
					.findByProperty("menu", cc);
			sz.add("" + submenus.size() + "");

			mm = new HashMap();
			mm.put("text", cc.getName());
			mm.put("tags", sz);
			mm.put("Id", cc.getMenuId());
			mm.put("selected", false);
			mm.put("href", "actionTo('" + cc.getMenuId() + "','2')");

			// 子公司
			if (submenus.size() > 0) {
				List sub_items = new ArrayList();
				List sbs = null;
				Map msub = null;
				for (int j = 0; j < submenus.size(); j++) {
					SubMenu scc = submenus.get(j);

					msub = new HashMap();
					msub.put("text", scc.getName());
					msub.put("Id", scc.getSubMenuId());
					msub.put("href", "actionTo('" + scc.getSubMenuId()
							+ "','3')");
					sub_items.add(msub);
				}

				mm.put("nodes", sub_items);
			}

			items.add(mm);

		}

		this.result.put("success", true);
		this.result.put("recordsTotal", ll.size());
		this.result.put("recordsFiltered", ll.size());
		this.result.put("data", items);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/menuDetail")
	@ResponseBody
	public Map menuDetail(ModelMap map, HttpSession session, Integer contentId,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Menu inn = this.webMananger.getMenuDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/subMenuDetail")
	@ResponseBody
	public Map subMenuDetail(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			SubMenu inn = this.webMananger.getSubMenuDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/roleTypeDetail")
	@ResponseBody
	public Map roleTypeDetail(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			RoleType inn = this.webMananger.getRoleTypeDAO()
					.findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveMenu")
	@ResponseBody
	public Map saveMenu(ModelMap map, HttpSession session, Integer type,
			Integer contentId, Menu com, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		Menu inn = null;
		if (contentId != null) {
			inn = this.webMananger.getMenuDAO().findById(contentId);
			inn.setName(com.getName());
			inn.setIcon(com.getIcon());
			inn.setHref(com.getHref());
			inn.setIsSelected(com.getIsSelected());
			inn.setType(com.getType());

			this.webMananger.getMenuDAO().saveOrUpdate(inn);
		} else {

			this.webMananger.getMenuDAO().save(com);
		}

		this.result.put("href", "actionTo('" + com.getMenuId() + "','2')");
		this.result.put("name", com.getName());
		this.result.put("Id", com.getMenuId());
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveSubMenu")
	@ResponseBody
	public Map saveSubMenu(ModelMap map, HttpSession session, Integer type,
			Integer contentId, SubMenu com, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		SubMenu inn = null;
		Menu menu = this.webMananger.getMenuDAO().findById(contentId);
		if (com.getSubMenuId() != null) {
			inn = this.webMananger.getSubMenuDAO().findById(com.getSubMenuId());
			inn.setMenu(menu);
			inn.setName(com.getName());
			inn.setAction(com.getAction());

			this.webMananger.getSubMenuDAO().saveOrUpdate(inn);
		} else {
			com.setMenu(menu);
			this.webMananger.getSubMenuDAO().save(com);
		}

		this.result.put("href", "actionTo('" + com.getSubMenuId() + "','3')");
		this.result.put("name", com.getName());
		this.result.put("Id", com.getSubMenuId());
		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveUserRole")
	@ResponseBody
	public Map saveUserRole(ModelMap map, HttpSession session,
			Integer contentId, Integer typeId, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();

		UserRole role = new UserRole();
		RoleType roleType = this.webMananger.getRoleTypeDAO().findById(typeId);
		SubMenu subMenu = this.webMananger.getSubMenuDAO().findById(contentId);
		List names = new ArrayList();
		names.add("roleType");
		names.add("subMenu");
		List values = new ArrayList();
		values.add(roleType);
		values.add(subMenu);
		List<UserRole> inns = this.webMananger.getUserRoleDAO()
				.findByPropertys(names, values);
		if (inns != null && inns.size() == 0) {
			role.setRoleType(roleType);
			role.setSubMenu(subMenu);

			this.webMananger.getUserRoleDAO().save(role);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveUserRoles")
	@ResponseBody
	public Map saveUserRoles(ModelMap map, HttpSession session, Integer[] ids,
			Integer typeId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		UserRole role = null;
		RoleType roleType = this.webMananger.getRoleTypeDAO().findById(typeId);
		List<UserRole> inns = this.webMananger.getUserRoleDAO().findByProperty(
				"roleType", roleType);
		if (inns != null && inns.size() > 0) {
			for (UserRole r : inns) {
				this.webMananger.getUserRoleDAO().delete(r);
			}

		}
		if (ids != null && ids.length > 0) {
			for (Integer id : ids) {
				role = new UserRole();
				SubMenu subMenu = this.webMananger.getSubMenuDAO().findById(id);

				role.setRoleType(roleType);
				role.setSubMenu(subMenu);

				this.webMananger.getUserRoleDAO().save(role);
			}
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteMenu")
	@ResponseBody
	public Map deleteMenu(ModelMap map, HttpSession session, Integer contentId,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Menu inn = this.webMananger.getMenuDAO().findById(contentId);
			this.webMananger.getMenuDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteSubMenu")
	@ResponseBody
	public Map deleteSubMenu(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			SubMenu inn = this.webMananger.getSubMenuDAO().findById(contentId);
			this.webMananger.getSubMenuDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteSMS")
	@ResponseBody
	public Map deleteSMS(ModelMap map, HttpSession session, Integer contentId,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Smsrecord inn = this.webMananger.getSmsRecordDAO().findById(
					contentId);
			this.webMananger.getSmsRecordDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/*
	 * @RequestMapping(value = "/manager/auditOutCome")
	 * 
	 * @ResponseBody public Map auditOutCome(ModelMap map, HttpSession session,
	 * Integer contentId, ServletRequest request, ServletResponse response) {
	 * this.result = new HashMap(); if (contentId != null) { Payoutlist inn =
	 * this.webMananger.getPayoutListDAO().findById( contentId); if
	 * (inn.getSuccess() == 0) { // boolean wxPayResult = false; // 发起微信企业零钱体现
	 * 
	 * String payResultStr = ""; boolean wxPayResult = false; try { payResultStr
	 * = TestWChatPayToUser.wechatPayForUser( ((int) (inn.getPmoney() * 100)) +
	 * "", inn.getPayCode(), inn.getOpenId(), inn.getPdesc()); } catch
	 * (Exception e) { // TODO Auto-generated catch block e.printStackTrace();
	 * wxPayResult = false; } if (payResultStr.equals("SUCCESS")) {
	 * inn.setSuccess((short) 1); inn.setSuccessTime(new Date());
	 * 
	 * this.webMananger.getPayoutListDAO().attachDirty(inn); this.status = 200;
	 * this.result.put("success", true); this.result.put("error", "");
	 * sendMessageToUser(inn.getAccount(), inn.getPtime(), inn.getPmoney()); }
	 * else { this.status = 201; this.message = "发放失败！"; } // wxPayResult = // }
	 * } else { this.status = 201; } return this.getResult(); }
	 * 
	 * @RequestMapping(value = "/manager/auditBatchOutCome")
	 * 
	 * @ResponseBody public Map auditBatchOutCome(ModelMap map, HttpSession
	 * session,
	 * 
	 * @RequestParam(value = "ids", required = false) Integer[] ids,
	 * ServletRequest request, ServletResponse response) { this.result = new
	 * HashMap(); if (ids != null && ids.length > 0) { for (Integer i = 0; i <
	 * ids.length; i++) { Integer contentId = ids[i]; if (contentId != null) {
	 * Payoutlist inn = this.webMananger.getPayoutListDAO()
	 * .findById(contentId); if (inn.getSuccess() == 0) { // boolean wxPayResult
	 * = false; // 发起微信企业零钱体现
	 * 
	 * String payResultStr = ""; boolean wxPayResult = false; try { payResultStr
	 * = TestWChatPayToUser.wechatPayForUser( ((int) (inn.getPmoney() * 100)) +
	 * "", inn.getPayCode(), inn.getOpenId(), inn.getPdesc()); } catch
	 * (Exception e) { // TODO Auto-generated catch // block
	 * e.printStackTrace(); wxPayResult = false; } if
	 * (payResultStr.equals("SUCCESS")) { inn.setSuccess((short) 1);
	 * inn.setSuccessTime(new Date());
	 * 
	 * this.webMananger.getPayoutListDAO() .attachDirty(inn); this.status = 200;
	 * sendMessageToUser(inn.getAccount(), inn.getPtime(), inn.getPmoney()); }
	 * else { this.status = 201; this.message = "发放失败！"; } } } } this.status =
	 * 200;
	 * 
	 * } else { this.result.put("success", true); this.result.put("error", "");
	 * this.status = 201; }
	 * 
	 * return this.getResult(); }
	 * 
	 * @RequestMapping(value = "/manager/auditOutProfit")
	 * 
	 * @ResponseBody public Map auditOutProfit(ModelMap map, HttpSession
	 * session, Integer contentId, ServletRequest request, ServletResponse
	 * response) { this.result = new HashMap(); if (contentId != null) { Profit
	 * inn = this.webMananger.getProfitDAO().findById(contentId); if
	 * (inn.getSuccess() == 0) { // boolean wxPayResult = false; // 发起微信企业零钱体现
	 * 
	 * String payResultStr = ""; boolean wxPayResult = false; try { payResultStr
	 * = TestWChatPayToUser.wechatPayForUser( ((int) (inn.getImoney() * 100)) +
	 * "", inn.getPayCode(), inn.getOpenId(), inn.getIdesc()); } catch
	 * (Exception e) { // TODO Auto-generated catch block e.printStackTrace();
	 * wxPayResult = false; } if (payResultStr.equals("SUCCESS")) {
	 * inn.setSuccess((short) 1); inn.setSuccessTime(new Date());
	 * 
	 * this.webMananger.getProfitDAO().attachDirty(inn); this.status = 200;
	 * sendMessageToUser(inn.getAccount(), inn.getItime(), inn.getImoney()); }
	 * else { this.status = 201; this.message = "发放失败！"; } // wxPayResult = // }
	 * }
	 * 
	 * this.result.put("success", true); this.result.put("error", "");
	 * this.status = 201; return this.getResult(); }
	 * 
	 * @RequestMapping(value = "/manager/auditOutProfits")
	 * 
	 * @ResponseBody public Map auditOutProfits(ModelMap map, HttpSession
	 * session,
	 * 
	 * @RequestParam(value = "ids", required = false) Integer[] ids,
	 * ServletRequest request, ServletResponse response) { this.result = new
	 * HashMap(); if (ids != null && ids.length > 0) { for (Integer i = 0; i <
	 * ids.length; i++) { Integer contentId = ids[i]; if (contentId != null) {
	 * Profit inn = this.webMananger.getProfitDAO().findById( contentId); if
	 * (inn.getSuccess() == 0) { // boolean wxPayResult = false; // 发起微信企业零钱体现
	 * 
	 * String payResultStr = ""; boolean wxPayResult = false; try { payResultStr
	 * = TestWChatPayToUser.wechatPayForUser( ((int) (inn.getImoney() * 100)) +
	 * "", inn.getPayCode(), inn.getOpenId(), inn.getIdesc()); } catch
	 * (Exception e) { // TODO Auto-generated catch // block
	 * e.printStackTrace(); wxPayResult = false; } if
	 * (payResultStr.equals("SUCCESS")) { inn.setSuccess((short) 1);
	 * inn.setSuccessTime(new Date());
	 * 
	 * this.webMananger.getProfitDAO().attachDirty(inn); this.status = 200;
	 * sendMessageToUser(inn.getAccount(), inn.getItime(), inn.getImoney()); }
	 * else { this.status = 201; this.message = "发放失败！"; } // wxPayResult = // }
	 * } } this.status = 200;
	 * 
	 * } else { this.result.put("success", true); this.result.put("error", "");
	 * this.status = 201; }
	 * 
	 * return this.getResult(); }
	 */
	private void sendMessageToUser(Account user, final Date time,
			final double money) {
		final Account _user = user;
		new Thread() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				String timeStr = DateUtils.dateToString(time,
						"yyyy-MM-dd HH:mm:ss");
				String content = String.format(
						AKConfig.STRING_EMIAL_DRAWSUCCESS, _user.getName(),
						timeStr, money);
				// 发送短信通知
				MsgUtil SMS = new MsgUtil(_user.getTel(), content,
						MessageType.NormalMessage);
				SMS.send();
			}

		}.run();
	}

	private void sendFinalMessageToAdmin() {
		new Thread() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				String timeStr = DateUtils.dateToString(new Date(),
						"yyyy-MM-dd HH:mm:ss");
				String content = String.format("截至:%s 微信商户平台运营资金余额不足，请尽快充值处理",
						timeStr);
				// 发送短信通知
				/*
				 * MsgUtil SMS = new MsgUtil("18165021666", content,
				 * MessageType.NormalMessage);
				 */
				
				MsgUtil SMS = new MsgUtil("18591218333", content,
						MessageType.NormalMessage);
				SMS.send();
			}

		}.run();
	}

	private void sendMessageToTec(final Integer orderId, final String name,
			final String con) {
		new Thread() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				String content = String.format("%s:%s订单%d存在异常，请及时查看", con,
						name, orderId);
				// 发送短信通知
				MsgUtil SMS = new MsgUtil("18729342354", content,
						MessageType.NormalMessage);
				SMS.send();
			}

		}.run();
	}

	@RequestMapping(value = "/manager/deleteNotice")
	@ResponseBody
	public Map deleteNotice(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Notice inn = this.webMananger.getNoticeDAO().findById(contentId);
			this.webMananger.getNoticeDAO().delete(inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/deleteUserRole")
	@ResponseBody
	public Map deleteUserRole(ModelMap map, HttpSession session,
			Integer typeId, Integer contentId, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			RoleType tt = this.webMananger.getRoleTypeDAO().findById(typeId);
			SubMenu menu = this.webMananger.getSubMenuDAO().findById(contentId);
			List names = new ArrayList();
			names.add("roleType");
			names.add("subMenu");
			List values = new ArrayList();
			values.add(tt);
			values.add(menu);
			List<UserRole> inns = this.webMananger.getUserRoleDAO()
					.findByPropertys(names, values);
			for (UserRole role : inns) {
				this.webMananger.getUserRoleDAO().delete(role);
			}
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	// 短信通知
	@RequestMapping(value = "/manager/SMSList")
	@ResponseBody
	public Map SMSList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		size = this.webMananger.getSmsRecordDAO().countAll();
		ll = this.webMananger.getSmsRecordDAO().findByPage(start, length);

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/noticeList")
	@ResponseBody
	public Map noticeList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		size = this.webMananger.getNoticeDAO().countAll();
		ll = this.webMananger.getNoticeDAO().findByPage(start, length);

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/noticeTypeList")
	@ResponseBody
	public Map noticeTypeList(ModelMap map, HttpSession session,

	@RequestParam(value = "type", required = false) Integer type,

	@RequestParam(value = "draw", required = false) Integer draw,

	@RequestParam(value = "start", required = false) Integer start,

	@RequestParam(value = "length", required = false) Integer length,

	@RequestParam(value = "search", required = false) String search,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();

		List ll = new ArrayList();
		Integer size = 0;
		size = this.webMananger.getnTypeDAOl().countAll();
		ll = this.webMananger.getnTypeDAOl().findAll();

		this.result.put("draw", draw);
		this.result.put("recordsTotal", size);
		this.result.put("recordsFiltered", size);
		this.result.put("data", ll);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getSMSDetail")
	@ResponseBody
	public Map getSMSDetail(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Smsrecord inn = this.webMananger.getSmsRecordDAO().findById(
					contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/getNoticeDetail")
	@ResponseBody
	public Map getNoticeDetail(ModelMap map, HttpSession session,
			Integer contentId, ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		if (contentId != null) {
			Notice inn = this.webMananger.getNoticeDAO().findById(contentId);
			this.result.put("data", inn);
		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveSmsRecord")
	@ResponseBody
	public Map saveSmsRecord(ModelMap map, HttpSession session,
			final String isall, final Integer[] mobiles, final String content,
			ServletRequest request, ServletResponse response) {
		this.result = new HashMap();
		Integer adminId = (Integer) session.getAttribute("adminId");
		final Admin admin = this.webMananger.getAdminDAO().findById(adminId);

		final AdminController self = this;
		new Thread() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				if (isall != null && isall.equalsIgnoreCase("on")) {
					List<Account> accounts = self.webMananger.getAccountDAO()
							.findAll();
					for (Account account : accounts) {
						Smsrecord record = new Smsrecord();
						record.setAdmin(admin);
						record.setContent(content);
						record.setSendtime(new Date());
						record.setMobile(account.getTel());
						Smstype tt = new Smstype();
						tt.setTypeId(1);

						record.setSmstype(tt);

						self.webMananger.getSmsRecordDAO().save(record);

						Tools.sendMessage(content, account.getTel());
					}

				} else {
					if (mobiles != null && mobiles.length > 0) {
						for (int i = 0; i < mobiles.length; i++) {
							Account account = self.webMananger.getAccountDAO()
									.findById(mobiles[i]);
							Smsrecord record = new Smsrecord();
							record.setAdmin(admin);
							record.setContent(content);
							record.setSendtime(new Date());
							record.setMobile(account.getTel());

							Smstype tt = new Smstype();
							tt.setTypeId(1);

							record.setSmstype(tt);
							self.webMananger.getSmsRecordDAO().save(record);

							Tools.sendMessage(content, account.getTel());
						}

					}
				}
			}

		}.start();

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	@RequestMapping(value = "/manager/saveNotice")
	@ResponseBody
	public Map saveNotice(ModelMap map, HttpSession session, Integer[] aid,
			final String ntitle, final String ncontent, String isall,
			Integer nidd, Integer nid, ServletRequest request,
			ServletResponse response) {
		this.result = new HashMap();

		if (nidd != null) {
			Integer adminId = (Integer) session.getAttribute("adminId");
			final Admin admin = this.webMananger.getAdminDAO()
					.findById(adminId);
			final Ntype type = this.webMananger.getnTypeDAOl().findById(nidd);
			if (isall != null && isall.equalsIgnoreCase("on")) {
				final AdminController _self = this;
				new Thread() {

					@Override
					public void run() {
						// TODO Auto-generated method stub
						super.run();
						List<Account> accounts = _self.webMananger
								.getAccountDAO().findAll();
						for (Account account : accounts) {
							if (account.getIsjob() != null
									&& account.getIsjob() == 1) {
								Notice notice = new Notice();
								notice.setNtitle(ntitle);
								notice.setNcontent(ncontent);
								notice.setNtype(type);
								notice.setNtime(new Date());
								notice.setAccount(account);
								notice.setNauthor(admin.getName());
								notice.setIsRead(0);

								_self.webMananger.getNoticeDAO().save(notice);
							}

						}

					}

				}.start();
			} else {
				if (aid != null && aid.length > 0) {
					for (Integer id : aid) {
						Account account = this.webMananger.getAccountDAO()
								.findById(id);

						Notice notice = new Notice();
						notice.setNtitle(ntitle);
						notice.setNcontent(ncontent);
						notice.setNtype(type);
						notice.setNtime(new Date());
						notice.setAccount(account);
						notice.setIsRead(0);
						notice.setNauthor(admin.getName());

						this.webMananger.getNoticeDAO().save(notice);

					}
				}
			}

		}

		this.result.put("success", true);
		this.result.put("error", "");

		this.status = 200;
		return this.getResult();
	}

	/***
	 * 如果余额不足时，给管理员发送短信通知
	 */
	private void sendNoEnoughMessageToAdmin() {
		Admin admin = this.webMananger.getAdminDAO().findById(24);
		if (admin != null) {
			String dateStr = DateUtils.dateToString(new Date(), "yyyy-MM-dd");
			dateStr += " 00:00:01";
			Date date;
			try {
				date = DateUtils.parseDate(dateStr);
				List<AdminNotice> notices = this.webMananger
						.getAdminNoticeDAO().findByPropertyAndTime("admin",
								admin, date);
				boolean flag = false;
				if (notices != null && notices.size() > 0) {
					for (AdminNotice adminNotice : notices) {
						Date date1 = adminNotice.getAddTime();
						Date date2 = new Date();
						long dinstance = DateUtils.minutesBetween(date1, date2);
						if (dinstance > 30) {
							flag = true;
						}
					}
				} else {
					flag = true;
				}

				if (flag) {
					sendFinalMessageToAdmin();
					AdminNotice notice = new AdminNotice();
					notice.setAddTime(new Date());
					notice.setContent("余额不足提醒！");
					notice.setAdmin(admin);

					this.webMananger.getAdminNoticeDAO().save(notice);
				}

			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}
